/**全局配置 Config */
import L from "leaflet";
import ScalarLayer from "@/utils/layer/ScalarLayer";
import ParticleLayer from "@/utils/layer/ParticleLayer";
import windFeatherLayer from "@/utils/layer/windFeatherLayer";
let Config = {
  ajaxTimeout: 6000,
  aniTime: 300, //动画时间

  AllLayers: null /**地图图层集合 */,
  ToolLayers: null /**工具图层集合 */,
  curData: {} /**当前时刻缓存数据 */,
  ImgData: {} /**数据缓存 */,
  ImgDate: "" /** 当前时间 */,
  TimeSlider: null /**时间滑条 */,
  typhoonYears: null,
  typhoonDatas: {},
  showLoading: () => {
    console.log("showLoading");
  },
  hideLoading: () => {
    console.log("hideLoading");
  },
  area: {} /** 当前区域信息 */,
  
  // 添加图层管理对象
  activeLayers: {} /**当前激活的图层集合 */,

  mapObj: {
    map: null /**地图对象 */,
    mapCenter: [] /**地图中心 */,
    // mapCenterGroup: {
    //   wenzhou: [27.7, 121.1],
    //   taizhou: [28.5, 121.76]
    // },
    // cityCenter: {
    //   wenzhou: [27.9911, 120.6993],
    //   taizhou: [28.6563, 121.4212]
    // },
    maxBound: L.latLngBounds(
      L.latLng(80, -3600),
      L.latLng(-80, 3600)
    ) /**地图范围 */,
    minZ: 3,
    maxZ: 14,
    zoom: 9,
    crs: L.CRS.EPSG3857,
    jxhzoom: 5,
    jxhzoomF: 5,
  },

  time: {
    /**时间配置 */ startTimeObj: "yyyy-MM-dd HH:00:00",
    endTimeObj: "yyyy-MM-dd HH:00:00",
    DateObj: "yyyy-MM-dd HH:00:00",
    dataTime: "2021050100",
    dataTimeUTC: "2021050100",
  },

  isShow: {
    isOnQuery: false /* 是否开启单点查询 */,
    allowParticle: false,
    wave: false,
    rwave: false,
    rtpwave: false,
    curRtpwave: "" /** 存储台风浪编号 [空，编号] */,
    waveType: "rwave",
    wind: "rwind",
    awind: "arwind",
    rcurrent: false,
    currentType: "rcurrent",
    surge: false,
    surgeType: "",
    curSurge: "" /** 存储风暴潮编号  [类型（最大、计算、潮位），编号，路径] */,
    tyInfoBox: false,
    tyInfoBoxshow: false,
    onSS: false,
    detail: {},
  },

  layerIndex: {
    baseMapIndex: 1,
    waveIndex: 10,
    waveDirParticle: 11,
    rwaveIndex: 12,
    rwaveDirParticle: 500,
    rtpwaveIndex: 14,
    rtpwaveDirParticle: 500,
    currentParticle: 16,
    rcurrentParticle: 17,
    tide: 18,
    surge: 18,
    windIndex: 22,
    windParticle: 24 /* 风场粒子 */,
    windFeatherIndex: 26 /* 风羽图 */,
    noSeaIndex: 20, //掩膜
    boundaryLine: 30, //海风边界矢量
    placeNameNote: 32,
    //overlayPane中canvas默认为100
  },

  rasterHeader: {
    global: {
      // startLon: 0.0,
      // endLon: 360.0,
      // startLat: 90,
      // endLat: -90,
      // scale: 0.25,
      // uscale: 0.25,
      // vscale: 0.25,
      // scaleStr: "-1.0"
      startLon: 119.6354,
      endLon: 124,
      startLat: 30.88738,
      endLat: 25.8696,
      uscale: 0.0044,
      vscale: 0.0052,
      pixel: 1000,
    },
    wave: {
      startLon: 99.0416,
      endLon: 137.04,
      startLat: 41.0416,
      endLat: 1.541666627,
      uscale: 0.08315,
      vscale: 0.08315,
      pixel: 475,
    },
    rcurrent: {
      startLon: 99.0416,
      endLon: 137.04,
      startLat: 41.0416,
      endLat: 1.541666627,
      uscale: 0.08315,
      vscale: 0.08315,
      scale: 0.08315,
      pixel: 475,
    },
    rtide: {
      startLon: 99.0416,
      endLon: 137.04,
      startLat: 41.0416,
      endLat: 1.541666627,
      uscale: 0.08315,
      vscale: 0.08315,
      pixel: 475,
    },
    arwind: {
      startLon: 99.0416,
      endLon: 137.04,
      startLat: 41.0416,
      endLat: 1.541666627,
      uscale: 0.08315,
      vscale: 0.08315,
      pixel: 475,
    },
    rwave: {
      startLon: 119.6,
      endLon: 124,
      startLat: 31,
      endLat: 25.8,
      uscale: 0.0044,
      vscale: 0.0052,
      pixel: 1000,
    },
    rtpwave: {
      startLon: 114,
      endLon: 133.8,
      startLat: 41,
      endLat: 16.2,
      uscale: 0.0198,
      vscale: 0.0248,
      pixel: 1000,
    },
    rwind: {
      startLon: 99.0416,
      endLon: 137.04,
      startLat: 41.0416,
      endLat: 1.541666627,
      uscale: 0.08315,
      vscale: 0.08315,
      pixel: 475,
    },
    rwindengry: {
      startLon: 99.0416,
      endLon: 137.04,
      startLat: 41.0416,
      endLat: 1.541666627,
      uscale: 0.08315,
      vscale: 0.08315,
      pixel: 475,
    },
    rgrade: {
      startLon: 99.0416,
      endLon: 137.04,
      startLat: 41.0416,
      endLat: 1.541666627,
      uscale: 0.08315,
      vscale: 0.08315,
      pixel: 475,
    },
    reffect: {
      startLon: 99.0416,
      endLon: 137.04,
      startLat: 41.0416,
      endLat: 1.541666627,
      uscale: 0.08315,
      vscale: 0.08315,
      pixel: 475,
    },
  },

  scalarColor: {
    wind: [
      {
        value: 0,
        color: "rgb(255,255,255)",
      },
      {
        value: 1,
        color: "rgb(193,231,249)",
      },
      {
        value: 2,
        color: "rgb(107,174,220)",
      },
      {
        value: 3,
        color: "rgb(72,160,139)",
      },
      {
        value: 4,
        color: "rgb(103,190,74)",
      },
      {
        value: 5,
        color: "rgb(241,229,91)",
      },
      {
        value: 6,
        color: "rgb(249,198,79)",
      },
      {
        value: 7,
        color: "rgb(245,109,42)",
      },
      {
        value: 8,
        color: "rgb(228,67,40)",
      },
      {
        value: 9,
        color: "rgb(188,39,65)",
      },
      {
        value: 10,
        color: "rgb(162,48,93)",
      },
    ],
    wind_speed: [
      {
        value: 0,
        color: "rgb(255,255,255)",
      },
      {
        value: 1,
        color: "rgb(193,231,249)",
      },
      {
        value: 2,
        color: "rgb(107,174,220)",
      },
      {
        value: 3,
        color: "rgb(72,160,139)",
      },
      {
        value: 4,
        color: "rgb(103,190,74)",
      },
      {
        value: 5,
        color: "rgb(241,229,91)",
      },
      {
        value: 6,
        color: "rgb(249,198,79)",
      },
      {
        value: 7,
        color: "rgb(245,109,42)",
      },
      {
        value: 8,
        color: "rgb(228,67,40)",
      },
      {
        value: 9,
        color: "rgb(188,39,65)",
      },
      {
        value: 10,
        color: "rgb(162,48,93)",
      },
    ],
    awind: [
      {
        value: 0,
        color: "rgb(255,255,255)",
      },
      {
        value: 2,
        color: "rgb(193,231,249)",
      },
      {
        value: 4,
        color: "rgb(107,174,220)",
      },
      {
        value: 6,
        color: "rgb(72,160,139)",
      },
      {
        value: 6,
        color: "rgb(103,190,74)",
      },
      {
        value: 10,
        color: "rgb(241,229,91)",
      },
      {
        value: 12,
        color: "rgb(249,198,79)",
      },
      {
        value: 14,
        color: "rgb(245,109,42)",
      },
      {
        value: 16,
        color: "rgb(228,67,40)",
      },
      {
        value: 18,
        color: "rgb(188,39,65)",
      },
      {
        value: 20,
        color: "rgb(162,48,93)",
      },
    ],
    windEngry: [
      {
        value: 0,
        color: "rgb(255,255,255)",
      },
      {
        value: 100,
        color: "rgb(193,231,249)",
      },
      {
        value: 200,
        color: "rgb(107,174,220)",
      },
      {
        value: 300,
        color: "rgb(72,160,139)",
      },
      {
        value: 400,
        color: "rgb(103,190,74)",
      },
      {
        value: 500,
        color: "rgb(241,229,91)",
      },
      {
        value: 600,
        color: "rgb(249,198,79)",
      },
      {
        value: 700,
        color: "rgb(245,109,42)",
      },
      {
        value: 800,
        color: "rgb(228,67,40)",
      },
      {
        value: 900,
        color: "rgb(188,39,65)",
      },
      {
        value: 1000,
        color: "rgb(162,48,93)",
      },
      // {
      //   "value": 21,
      //   "color": "rgb(255, 206, 53)"
      // }, {
      //   "value": 24,
      //   "color": "rgb(255, 164, 62)"
      // }, {
      //   "value": 27,
      //   "color": "rgb(233, 123, 72)"
      // }, {
      //   "value": 30,
      //   "color": "rgb(204,90,99)"
      // }, {
      //   "value": 33,
      //   "color": "rgb(169,56,94)"
      // }, {
      //   "value": 36,
      //   "color": "rgb(143,33,76)"
      // }, {
      //   "value": 39,
      //   "color": "rgb(105,25,34)"
      // }, {
      //   "value": 50,
      //   "color": "rgb(43,0,1)"
      // }],
    ],
    grade: [
      {
        value: 1,
        color: "rgb(107,174,220)",
      },
      {
        value: 2,
        color: "rgb(72,160,139)",
      },
      {
        value: 3,
        color: "rgb(103,190,74)",
      },
      {
        value: 4,
        color: "rgb(249,198,79)",
      },
      {
        value: 5,
        color: "rgb(245,109,42)",
      },
      {
        value: 6,
        color: "rgb(188,39,65)",
      },
      {
        value: 7,
        color: "rgb(162,48,93)",
      },
    ],
    effect: [
      {
        value: 0,
        color: "rgb(255,255,255)",
      },
      {
        value: 50,
        color: "rgb(193,231,249)",
      },
      {
        value: 60,
        color: "rgb(107,174,220)",
      },
      {
        value: 70,
        color: "rgb(103,190,74)",
      },
      {
        value: 80,
        color: "rgb(249,198,79)",
      },
      {
        value: 90,
        color: "rgb(228,67,40)",
      },
      {
        value: 100,
        color: "rgb(162,48,93)",
      },
    ],
    wave: [
      // { "color": "rgb(0, 31, 255)", "value": 0 },
      // { "color": "rgb(71, 94, 255)", "value": 1 },
      // { "color": "rgb(54, 152, 237)", "value": 2 },
      // { "color": "rgb(253, 255, 0)", "value": 3 },
      // { "color": "rgb(208, 88, 44)", "value": 4 },
      // { "color": "rgb(250, 11, 10)", "value": 5 },
      // { "color": "rgb(187, 13, 19)", "value": 6 }

      { color: "rgb(2, 239, 204)", value: 0 },
      { color: "rgb(7, 193, 59)", value: 0.2 },
      { color: "rgb(110, 210, 9)", value: 0.4 },
      { color: "rgb(255, 255, 0)", value: 0.8 },
      { color: "rgb(255, 200, 0)", value: 1 },
      { color: "rgb(255, 130, 0)", value: 1.2 },
      { color: "rgb(255, 30, 0)", value: 1.4 },
      { color: "rgb(184,0,58)", value: 2 },
      { color: "rgb(87,0,136)", value: 3 },
    ],
    rwave: [
      { color: "rgb(0, 0, 232)", value: 0 },
      { color: "rgb(0, 71, 255)", value: 0.5 },
      { color: "rgb(0, 162, 255)", value: 1 },
      { color: "rgb(0, 255, 255)", value: 1.5 },
      { color: "rgb(91, 255, 163)", value: 2 },
      { color: "rgb(185, 255, 69)", value: 2.5 },
      { color: "rgb(0, 255, 0)", value: 3 },
      { color: "rgb(128,255,0)", value: 3.5 },
      { color: "rgb(255, 255, 0)", value: 4 },
      { color: "rgb(255, 143, 0)", value: 5 },
      { color: "rgb(210, 0, 0)", value: 7 },
      { color: "rgb(132, 21, 22)", value: 10 },
    ],
    rtpwave: [
      { color: "rgb(0, 31, 255)", value: 0 },
      { color: "rgb(71, 94, 255)", value: 2 },
      { color: "rgb(54, 152, 237)", value: 3 },
      { color: "rgb(253, 255, 0)", value: 4 },
      { color: "rgb(208, 88, 44)", value: 6 },
      { color: "rgb(250, 11, 10)", value: 9 },
      { color: "rgb(187, 13, 19)", value: 14 },
    ],
    windFeather: [
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 64,
        g: 131,
        b: 184,
      },
      {
        r: 65,
        g: 133,
        b: 182,
      },
      {
        r: 66,
        g: 134,
        b: 181,
      },
      {
        r: 65,
        g: 136,
        b: 180,
      },
      {
        r: 66,
        g: 138,
        b: 178,
      },
      {
        r: 67,
        g: 139,
        b: 177,
      },
      {
        r: 68,
        g: 141,
        b: 174,
      },
      {
        r: 69,
        g: 142,
        b: 174,
      },
      {
        r: 69,
        g: 145,
        b: 171,
      },
      {
        r: 70,
        g: 146,
        b: 170,
      },
      {
        r: 70,
        g: 147,
        b: 167,
      },
      {
        r: 72,
        g: 149,
        b: 167,
      },
      {
        r: 72,
        g: 149,
        b: 165,
      },
      {
        r: 72,
        g: 152,
        b: 163,
      },
      {
        r: 73,
        g: 153,
        b: 160,
      },
      {
        r: 74,
        g: 155,
        b: 159,
      },
      {
        r: 75,
        g: 156,
        b: 157,
      },
      {
        r: 74,
        g: 159,
        b: 156,
      },
      {
        r: 75,
        g: 160,
        b: 153,
      },
      {
        r: 75,
        g: 161,
        b: 150,
      },
      {
        r: 76,
        g: 162,
        b: 149,
      },
      {
        r: 77,
        g: 164,
        b: 147,
      },
      {
        r: 77,
        g: 166,
        b: 146,
      },
      {
        r: 78,
        g: 168,
        b: 143,
      },
      {
        r: 79,
        g: 169,
        b: 141,
      },
      {
        r: 80,
        g: 171,
        b: 140,
      },
      {
        r: 78,
        g: 172,
        b: 136,
      },
      {
        r: 78,
        g: 173,
        b: 133,
      },
      {
        r: 78,
        g: 174,
        b: 128,
      },
      {
        r: 78,
        g: 175,
        b: 124,
      },
      {
        r: 77,
        g: 176,
        b: 121,
      },
      {
        r: 77,
        g: 177,
        b: 115,
      },
      {
        r: 76,
        g: 178,
        b: 112,
      },
      {
        r: 77,
        g: 180,
        b: 109,
      },
      {
        r: 77,
        g: 181,
        b: 104,
      },
      {
        r: 75,
        g: 182,
        b: 100,
      },
      {
        r: 75,
        g: 183,
        b: 97,
      },
      {
        r: 74,
        g: 185,
        b: 93,
      },
      {
        r: 74,
        g: 186,
        b: 88,
      },
      {
        r: 76,
        g: 186,
        b: 87,
      },
      {
        r: 78,
        g: 186,
        b: 85,
      },
      {
        r: 79,
        g: 187,
        b: 85,
      },
      {
        r: 79,
        g: 188,
        b: 83,
      },
      {
        r: 81,
        g: 188,
        b: 82,
      },
      {
        r: 82,
        g: 190,
        b: 81,
      },
      {
        r: 83,
        g: 189,
        b: 79,
      },
      {
        r: 86,
        g: 190,
        b: 79,
      },
      {
        r: 87,
        g: 191,
        b: 78,
      },
      {
        r: 87,
        g: 191,
        b: 76,
      },
      {
        r: 89,
        g: 192,
        b: 74,
      },
      {
        r: 91,
        g: 192,
        b: 74,
      },
      {
        r: 92,
        g: 193,
        b: 73,
      },
      {
        r: 94,
        g: 194,
        b: 72,
      },
      {
        r: 96,
        g: 194,
        b: 73,
      },
      {
        r: 98,
        g: 194,
        b: 71,
      },
      {
        r: 101,
        g: 195,
        b: 73,
      },
      {
        r: 103,
        g: 195,
        b: 71,
      },
      {
        r: 105,
        g: 195,
        b: 72,
      },
      {
        r: 107,
        g: 195,
        b: 73,
      },
      {
        r: 110,
        g: 196,
        b: 73,
      },
      {
        r: 111,
        g: 197,
        b: 74,
      },
      {
        r: 115,
        g: 197,
        b: 73,
      },
      {
        r: 117,
        g: 197,
        b: 74,
      },
      {
        r: 118,
        g: 198,
        b: 73,
      },
      {
        r: 119,
        g: 198,
        b: 73,
      },
      {
        r: 123,
        g: 200,
        b: 72,
      },
      {
        r: 127,
        g: 199,
        b: 73,
      },
      {
        r: 128,
        g: 200,
        b: 72,
      },
      {
        r: 131,
        g: 200,
        b: 71,
      },
      {
        r: 134,
        g: 201,
        b: 70,
      },
      {
        r: 136,
        g: 202,
        b: 70,
      },
      {
        r: 139,
        g: 202,
        b: 71,
      },
      {
        r: 142,
        g: 204,
        b: 71,
      },
      {
        r: 143,
        g: 203,
        b: 69,
      },
      {
        r: 147,
        g: 205,
        b: 69,
      },
      {
        r: 150,
        g: 204,
        b: 67,
      },
      {
        r: 153,
        g: 205,
        b: 68,
      },
      {
        r: 154,
        g: 205,
        b: 68,
      },
      {
        r: 158,
        g: 206,
        b: 68,
      },
      {
        r: 160,
        g: 207,
        b: 67,
      },
      {
        r: 163,
        g: 208,
        b: 66,
      },
      {
        r: 165,
        g: 208,
        b: 67,
      },
      {
        r: 169,
        g: 208,
        b: 67,
      },
      {
        r: 171,
        g: 208,
        b: 66,
      },
      {
        r: 174,
        g: 209,
        b: 65,
      },
      {
        r: 176,
        g: 210,
        b: 64,
      },
      {
        r: 178,
        g: 210,
        b: 65,
      },
      {
        r: 182,
        g: 212,
        b: 66,
      },
      {
        r: 183,
        g: 211,
        b: 64,
      },
      {
        r: 188,
        g: 212,
        b: 64,
      },
      {
        r: 188,
        g: 212,
        b: 64,
      },
      {
        r: 190,
        g: 212,
        b: 65,
      },
      {
        r: 192,
        g: 212,
        b: 65,
      },
      {
        r: 193,
        g: 211,
        b: 63,
      },
      {
        r: 195,
        g: 211,
        b: 63,
      },
      {
        r: 197,
        g: 211,
        b: 64,
      },
      {
        r: 197,
        g: 211,
        b: 62,
      },
      {
        r: 199,
        g: 211,
        b: 63,
      },
      {
        r: 201,
        g: 211,
        b: 63,
      },
      {
        r: 202,
        g: 210,
        b: 62,
      },
      {
        r: 204,
        g: 210,
        b: 62,
      },
      {
        r: 206,
        g: 210,
        b: 63,
      },
      {
        r: 206,
        g: 210,
        b: 63,
      },
      {
        r: 205,
        g: 209,
        b: 62,
      },
      {
        r: 206,
        g: 208,
        b: 62,
      },
      {
        r: 207,
        g: 207,
        b: 61,
      },
      {
        r: 208,
        g: 208,
        b: 62,
      },
      {
        r: 208,
        g: 205,
        b: 62,
      },
      {
        r: 208,
        g: 205,
        b: 62,
      },
      {
        r: 209,
        g: 204,
        b: 61,
      },
      {
        r: 209,
        g: 204,
        b: 61,
      },
      {
        r: 210,
        g: 203,
        b: 61,
      },
      {
        r: 209,
        g: 202,
        b: 60,
      },
      {
        r: 210,
        g: 201,
        b: 60,
      },
      {
        r: 211,
        g: 199,
        b: 61,
      },
      {
        r: 211,
        g: 199,
        b: 61,
      },
      {
        r: 212,
        g: 199,
        b: 61,
      },
      {
        r: 212,
        g: 199,
        b: 61,
      },
      {
        r: 213,
        g: 197,
        b: 60,
      },
      {
        r: 213,
        g: 197,
        b: 62,
      },
      {
        r: 213,
        g: 195,
        b: 61,
      },
      {
        r: 214,
        g: 194,
        b: 61,
      },
      {
        r: 213,
        g: 193,
        b: 60,
      },
      {
        r: 215,
        g: 192,
        b: 62,
      },
      {
        r: 215,
        g: 190,
        b: 61,
      },
      {
        r: 215,
        g: 190,
        b: 61,
      },
      {
        r: 216,
        g: 189,
        b: 60,
      },
      {
        r: 216,
        g: 188,
        b: 62,
      },
      {
        r: 216,
        g: 187,
        b: 61,
      },
      {
        r: 216,
        g: 184,
        b: 61,
      },
      {
        r: 215,
        g: 183,
        b: 62,
      },
      {
        r: 216,
        g: 181,
        b: 63,
      },
      {
        r: 216,
        g: 179,
        b: 62,
      },
      {
        r: 215,
        g: 178,
        b: 63,
      },
      {
        r: 216,
        g: 176,
        b: 63,
      },
      {
        r: 216,
        g: 174,
        b: 64,
      },
      {
        r: 215,
        g: 173,
        b: 65,
      },
      {
        r: 214,
        g: 170,
        b: 63,
      },
      {
        r: 216,
        g: 169,
        b: 65,
      },
      {
        r: 215,
        g: 167,
        b: 65,
      },
      {
        r: 215,
        g: 165,
        b: 66,
      },
      {
        r: 216,
        g: 164,
        b: 65,
      },
      {
        r: 215,
        g: 162,
        b: 66,
      },
      {
        r: 215,
        g: 161,
        b: 65,
      },
      {
        r: 215,
        g: 159,
        b: 66,
      },
      {
        r: 215,
        g: 158,
        b: 68,
      },
      {
        r: 214,
        g: 157,
        b: 67,
      },
      {
        r: 215,
        g: 155,
        b: 67,
      },
      {
        r: 214,
        g: 154,
        b: 68,
      },
      {
        r: 214,
        g: 152,
        b: 69,
      },
      {
        r: 213,
        g: 151,
        b: 68,
      },
      {
        r: 214,
        g: 149,
        b: 69,
      },
      {
        r: 214,
        g: 149,
        b: 69,
      },
      {
        r: 214,
        g: 147,
        b: 69,
      },
      {
        r: 214,
        g: 147,
        b: 69,
      },
      {
        r: 214,
        g: 145,
        b: 70,
      },
      {
        r: 213,
        g: 144,
        b: 69,
      },
      {
        r: 213,
        g: 143,
        b: 71,
      },
      {
        r: 214,
        g: 142,
        b: 70,
      },
      {
        r: 214,
        g: 141,
        b: 72,
      },
      {
        r: 214,
        g: 139,
        b: 71,
      },
      {
        r: 214,
        g: 139,
        b: 72,
      },
      {
        r: 213,
        g: 138,
        b: 71,
      },
      {
        r: 215,
        g: 137,
        b: 73,
      },
      {
        r: 214,
        g: 136,
        b: 72,
      },
      {
        r: 215,
        g: 135,
        b: 74,
      },
      {
        r: 213,
        g: 133,
        b: 72,
      },
      {
        r: 214,
        g: 132,
        b: 74,
      },
      {
        r: 213,
        g: 131,
        b: 73,
      },
      {
        r: 215,
        g: 130,
        b: 75,
      },
      {
        r: 214,
        g: 129,
        b: 74,
      },
      {
        r: 214,
        g: 129,
        b: 75,
      },
      {
        r: 214,
        g: 127,
        b: 74,
      },
      {
        r: 213,
        g: 125,
        b: 75,
      },
      {
        r: 213,
        g: 125,
        b: 75,
      },
      {
        r: 214,
        g: 123,
        b: 76,
      },
      {
        r: 214,
        g: 123,
        b: 76,
      },
      {
        r: 214,
        g: 121,
        b: 77,
      },
      {
        r: 214,
        g: 121,
        b: 77,
      },
      {
        r: 213,
        g: 120,
        b: 77,
      },
      {
        r: 214,
        g: 118,
        b: 78,
      },
      {
        r: 213,
        g: 116,
        b: 81,
      },
      {
        r: 213,
        g: 114,
        b: 82,
      },
      {
        r: 211,
        g: 112,
        b: 83,
      },
      {
        r: 211,
        g: 109,
        b: 84,
      },
      {
        r: 210,
        g: 108,
        b: 85,
      },
      {
        r: 211,
        g: 106,
        b: 87,
      },
      {
        r: 208,
        g: 105,
        b: 88,
      },
      {
        r: 209,
        g: 103,
        b: 89,
      },
      {
        r: 208,
        g: 102,
        b: 89,
      },
      {
        r: 208,
        g: 99,
        b: 92,
      },
      {
        r: 206,
        g: 97,
        b: 92,
      },
      {
        r: 207,
        g: 95,
        b: 94,
      },
      {
        r: 206,
        g: 93,
        b: 95,
      },
      {
        r: 206,
        g: 91,
        b: 98,
      },
      {
        r: 205,
        g: 89,
        b: 98,
      },
      {
        r: 203,
        g: 87,
        b: 100,
      },
      {
        r: 203,
        g: 84,
        b: 103,
      },
      {
        r: 202,
        g: 83,
        b: 103,
      },
      {
        r: 203,
        g: 81,
        b: 106,
      },
      {
        r: 202,
        g: 79,
        b: 107,
      },
      {
        r: 201,
        g: 78,
        b: 109,
      },
      {
        r: 200,
        g: 75,
        b: 109,
      },
      {
        r: 199,
        g: 73,
        b: 111,
      },
      {
        r: 200,
        g: 71,
        b: 112,
      },
      {
        r: 197,
        g: 70,
        b: 111,
      },
      {
        r: 196,
        g: 69,
        b: 110,
      },
      {
        r: 195,
        g: 68,
        b: 109,
      },
      {
        r: 194,
        g: 67,
        b: 108,
      },
      {
        r: 193,
        g: 68,
        b: 108,
      },
      {
        r: 192,
        g: 67,
        b: 107,
      },
      {
        r: 191,
        g: 66,
        b: 106,
      },
      {
        r: 188,
        g: 66,
        b: 105,
      },
      {
        r: 187,
        g: 65,
        b: 104,
      },
      {
        r: 186,
        g: 66,
        b: 104,
      },
      {
        r: 185,
        g: 65,
        b: 103,
      },
      {
        r: 184,
        g: 64,
        b: 102,
      },
      {
        r: 182,
        g: 63,
        b: 101,
      },
      {
        r: 181,
        g: 62,
        b: 100,
      },
      {
        r: 180,
        g: 61,
        b: 99,
      },
      {
        r: 180,
        g: 61,
        b: 99,
      },
      {
        r: 176,
        g: 60,
        b: 99,
      },
      {
        r: 176,
        g: 60,
        b: 97,
      },
      {
        r: 175,
        g: 59,
        b: 96,
      },
      {
        r: 174,
        g: 58,
        b: 95,
      },
      {
        r: 172,
        g: 58,
        b: 94,
      },
      {
        r: 171,
        g: 56,
        b: 95,
      },
      {
        r: 170,
        g: 55,
        b: 94,
      },
      {
        r: 168,
        g: 56,
        b: 92,
      },
      {
        r: 167,
        g: 55,
        b: 93,
      },
      {
        r: 167,
        g: 55,
        b: 93,
      },
      {
        r: 165,
        g: 55,
        b: 92,
      },
      {
        r: 165,
        g: 55,
        b: 92,
      },
      {
        r: 166,
        g: 54,
        b: 92,
      },
      {
        r: 166,
        g: 54,
        b: 92,
      },
      {
        r: 164,
        g: 54,
        b: 91,
      },
      {
        r: 164,
        g: 54,
        b: 91,
      },
      {
        r: 164,
        g: 54,
        b: 91,
      },
      {
        r: 164,
        g: 54,
        b: 91,
      },
      {
        r: 163,
        g: 53,
        b: 90,
      },
      {
        r: 163,
        g: 53,
        b: 90,
      },
      {
        r: 163,
        g: 53,
        b: 90,
      },
    ],
    surge: [
      {
        value: -50,
        color: "rgb(0,0,143)",
      },
      {
        value: 0,
        color: "rgb(0, 48, 255)",
      },
      {
        value: 50,
        color: "rgb(0, 223, 255)",
      },
      {
        value: 100,
        color: "rgb(143, 255, 112)",
      },
      {
        value: 150,
        color: "rgb(255, 207, 0)",
      },
      {
        value: 200,
        color: "rgb(255, 32, 0)",
      },
      {
        value: 250,
        color: "rgb(128, 0, 0)",
      },
    ],
    current: [
      { color: "RGB(82,71,141)", value: 0 },
      { color: "RGB(85,78,177)", value: 0.4 },
      { color: "RGB(67,105,196)", value: 0.8 },
      { color: "RGB(64,160,180)", value: 1.2 },
      { color: "RGB(78,194,98)", value: 1.6 },
      { color: "RGB(149,219,70)", value: 2 },
      { color: "RGB(220,234,55)", value: 2.4 },
      { color: "RGB(235,192,56)", value: 2.8 },
      { color: "RGB(234,164,62)", value: 3.2 },
      { color: "RGB(233,123,72)", value: 3.6 },
      { color: "RGB(225,94,93)", value: 4 },
      { color: "RGB(190,58,102)", value: 4.4 },
    ],
    current_speed: [
      { color: "RGB(82,71,141)", value: 0 },
      { color: "RGB(85,78,177)", value: 0.4 },
      { color: "RGB(67,105,196)", value: 0.8 },
      { color: "RGB(64,160,180)", value: 1.2 },
      { color: "RGB(78,194,98)", value: 1.6 },
      { color: "RGB(149,219,70)", value: 2 },
      { color: "RGB(220,234,55)", value: 2.4 },
      { color: "RGB(235,192,56)", value: 2.8 },
      { color: "RGB(234,164,62)", value: 3.2 },
      { color: "RGB(233,123,72)", value: 3.6 },
      { color: "RGB(225,94,93)", value: 4 },
      { color: "RGB(190,58,102)", value: 4.4 },
    ],
    seatemp: [
      { "value": -3, "color": "rgb(190,190,190)" },
      { "value": -1, "color": "rgb(167,169,182)" },
      { "value": 1, "color": "rgb(142,141,172)" },
      { "value": 3, "color": "rgb(110,93,145)" },
      { "value": 5, "color": "rgb(44,36,96)" },
      { "value": 7, "color": "rgb(59,54,121)" },
      { "value": 9, "color": "rgb(68,76,141)" },
      { "value": 11, "color": "rgb(66,96,150)" },
      { "value": 13, "color": "rgb(63,120,149)" },
      { "value": 15, "color": "rgb(69,141,127)" },
      { "value": 17, "color": "rgb(76,157,101)" },
      { "value": 19, "color": "rgb(94,167,78)" },
      { "value": 21, "color": "rgb(129,176,64)" },
      { "value": 23, "color": "rgb(168,179,57)" },
      { "value": 25, "color": "rgb(181,168,54)" },
      { "value": 27, "color": "rgb(187,154,57)" },
      { "value": 29, "color": "rgb(185,138,60)" },
      { "value": 31, "color": "rgb(185,115,64)" },
      { "value": 33, "color": "rgb(180,91,77)" },
      { "value": 35, "color": "rgb(168,69,89)" },
      { "value": 37, "color": "rgb(148,53,85)" },
      { "value": 39, "color": "rgb(127,38,68)" },
  ],
  },
};
export default Config;
let map = null,
  thisUData = [],
  thisVData = [],
  thisGridData = [];
export const initMap = () => {
  Config.AllLayers = {
    surgeLayer: ScalarLayer({
      //増水
      scalarColor: Config.scalarColor.surge,
      zindex: 99,
      opacity: 0.9,
      type: "surge",
      surgeTP: "",
      showLabel: false,
      magnification: 1, //画布缩放比例
    }),
    currentLayer: ParticleLayer({
      //精细化流场粒子
      zindex: 99,
      magnification: 1, //画布缩放比例
      color: ["rgba(255,81,0,1)"],
      velocityScale: 0.08, //步长，流动速度(尽量不变)
      globalAlpha: 0.9, //全局透明度
      particleAge: 60, //粒子生命周期
      particleMultiplier: 600, //密度
      frame_rate: 20, //刷新率
      lineWidth: 1, //线宽
      type: "current",
    }),
    waveLayer: ScalarLayer({
      //浪
      scalarColor: Config.scalarColor.wave,
      zindex: 99,
      opacity: 1.0,
      type: "wave",
      showLabel: false,
      magnification: 1,
    }),
    awindLayer: ScalarLayer({
      //预报风
      scalarColor: Config.scalarColor.awind,
      zindex: 99,
      opacity: 1.0,
      type: "awind",
      showLabel: false,
      magnification: 1,
    }),
    windLayer: ScalarLayer({
      //风
      scalarColor: Config.scalarColor.wind,
      zindex: 99,
      opacity: 1.0,
      type: "wind",
      showLabel: false,
      magnification: 1,
    }),
    windEngryLayer: ScalarLayer({
      //风功率
      scalarColor: Config.scalarColor.windEngry,
      zindex: 99,
      opacity: 1.0,
      type: "windEngry",
      showLabel: false,
      magnification: 1,
    }),
    gradeLayer: ScalarLayer({
      //等级
      scalarColor: Config.scalarColor.grade,
      zindex: 99,
      opacity: 1.0,
      type: "grade",
      showLabel: false,
      magnification: 1,
    }),
    effectLayer: ScalarLayer({
      //有效风时
      scalarColor: Config.scalarColor.effect,
      zindex: 99,
      opacity: 1.0,
      type: "effect",
      showLabel: false,
      magnification: 1,
    }),
    tianditu_v: L.tileLayer(
      "https://www.oceanread.com:444/esriCOC/{z}/{y}/{x}.png",
      {
        //   maxZoom: 10,
        //   minZoom: 2,
      }
    ),
    tianditu_v_nosea: L.tileLayer(
      "http://www.oceanread.com:8066/esriCOC_withoutsea/{z}/{y}/{x}.png",
      {
        pane: "overlayPane",
        zIndex: 100,
      }
    ),
  };
  map = L.map("map", {
    attributionControl: false,
    crs: L.CRS.EPSG3857,
    zoomControl: false,
    renderer: L.canvas(),
    // 全屏
    fullscreenControl: false,
  }).setView([30.954039, 121.933231], 6);
  Config.mapObj.map = map;
  Config.AllLayers.tianditu_v.addTo(Config.mapObj.map);
  Config.ToolLayers = L.layerGroup().addTo(Config.mapObj.map);
};
/**当前绘图的图层组 */
let thisLayerG = L.layerGroup();
export const addForecastLayer = (pa) => {
  // 生成图层唯一标识
  const layerKey = `${pa.label}_${pa.attribute.type}_${JSON.stringify(pa.attribute)}`;
  
  // 检查图层是否已经存在
  if (Config.activeLayers[layerKey]) {
    // console.log(`图层 ${pa.label} 已经存在，跳过重复添加`);
    return;
  }
  
  thisLayerG.addTo(Config.mapObj.map);
  let pngUrl = `${pa.common.url}`;
  let dataType = pa.attribute.type;
  let calRegion = pa.attribute.calRegion;
  let dataRange = pa.common.range;
  let image = new Image();
  image.crossOrigin = "Anonymous";
  image.src = pngUrl;
  image.onload = function () {
    let can = document.createElement("canvas");
    can.width = image.width;
    can.height = image.height;
    let ImgdataCtx = can.getContext("2d");
    ImgdataCtx.drawImage(image, 0, 0);
    let image0 = ImgdataCtx.getImageData(0, 0, image.width, image.height);
    let imgdat0 = image0.data;

    if (dataType == "wind") {
      thisUData = [];
      thisVData = [];
      let k = -1;
      for (let i = 0; i < image0.height; i++) {
        for (let j = 0; j < image0.width; j++) {
          k++;
          let x = i * 4 * image0.width + j * 4;
          let r = imgdat0[x],
            g = imgdat0[x + 1],
            b = imgdat0[x + 2],
            a = imgdat0[x + 3];
          let u = b >= 10 ? r / 10 : -(r / 10);
          let v = b % 10 == 1 ? g / 10 : -(g / 10);
          thisUData[k] = u;
          thisVData[k] = v;
        }
      }
      if (pa.attribute.showFeather) {
        // TODO
      }
    } else if (dataType == "current") {
      thisUData = [];
      thisVData = [];
      let k = -1;
      for (let i = 0; i < image0.height; i++) {
        for (let j = 0; j < image0.width; j++) {
          k++;
          let x = i * 4 * image0.width + j * 4;
          let r = imgdat0[x],
            g = imgdat0[x + 1],
            b = imgdat0[x + 2],
            a = imgdat0[x + 3];
          let u = 0,
            v = 0;
          if (a != 0) {
            u = r / 100.0;
            v = g / 100.0;
            if (b == 0) {
              u = -u;
              v = -v;
            } else if (b == 1) {
              u = -u;
            } else if (b == 10) {
              v = -v;
            }
          }
          thisUData[k] = u;
          thisVData[k] = v;
        }
      }
    } else {
      thisGridData = [];
      for (let i = 0; i < image0.height; i++) {
        thisGridData[i] = [];
        for (let j = 0; j < image0.width; j++) {
          let x = i * 4 * image0.width + j * 4;
          let r = imgdat0[x],
            g = imgdat0[x + 1],
            b = imgdat0[x + 2],
            a = imgdat0[x + 3];
          let value_0 = -999;
          if (dataType == "wave") {
            value_0 = r + g / 100;
          } else if (dataType == "seatemp") {
            value_0 = r + g + b / 100.0 - 273.15;
          } else if (dataType == "temp") {
            value_0 = r + g + b / 100.0 - 273.15;
          } else if (dataType == "tide") {
            value_0 = r + g / 100.0;
            if (b == 200.0) {
              value_0 = -value_0;
            }
          } else if (dataType == "sealevel") {
            value_0 = r / 100.0;
            if (b == 0 || b == 1) {
              value_0 = -value_0;
            }
          } else if (dataType == "wind_speed") {
            let u = b >= 10 ? r / 10 : -(r / 10);
            let v = b % 10 == 1 ? g / 10 : -(g / 10);
            value_0 = Math.sqrt(u * u + v * v);
          } else if (dataType == "current_speed") {
            let u = 0,
              v = 0;
            if (a != 0) {
              u = r / 100.0;
              v = g / 100.0;
              if (b == 0) {
                u = -u;
                v = -v;
              } else if (b == 1) {
                u = -u;
              } else if (b == 10) {
                v = -v;
              }
            }
            value_0 = Math.sqrt(u * u + v * v);
          }
          // if (a == 0) {
          //   value_0 = -999;
          // }
          thisGridData[i][j] = value_0.toFixed(1);
        }
      }
    }
    if (pa.attribute.showFeather) {
      thisGridData = [];
      for (let i = 0; i < image0.height; i++) {
        thisGridData[i] = [];
        for (let j = 0; j < image0.width; j++) {
          let x = i * 4 * image0.width + j * 4;
          let r = imgdat0[x],
            g = imgdat0[x + 1],
            b = imgdat0[x + 2],
            a = imgdat0[x + 3];
          let value_0 = -999;
          // if (dataType == "wave") {
          //   value_0 = r + g / 100;
          // } else if (dataType == "seatemp") {
          //   value_0 = r + g + b / 100.0 - 273.15;
          // } else if (dataType == "temp") {
          //   value_0 = r + g + b / 100.0 - 273.15;
          // } else if (dataType == "tide") {
          //   value_0 = r + g / 100.0;
          //   if (b == 200.0) {
          //     value_0 = -value_0;
          //   }
          // } else if (dataType == "sealevel") {
          //   value_0 = r / 100.0;
          //   if (b == 0 || b == 1) {
          //     value_0 = -value_0;
          //   }
          // } else if (dataType == "wind_speed" || dataType == "wind") {
          //   let u = b >= 10 ? r / 10 : -(r / 10);
          //   let v = b % 10 == 1 ? g / 10 : -(g / 10);
          //   value_0 = Math.sqrt(u * u + v * v);
          // }
          // if (a == 0) {
          //   value_0 = -999;
          // }
          if (dataType == "wind") {
            let u = b >= 10 ? r / 10 : -(r / 10);
            let v = b % 10 == 1 ? g / 10 : -(g / 10);
            value_0 = { u: u, v, v };
            thisGridData[i][j] = value_0;
          }
          if (dataType == "current") {
            let u = 0,
              v = 0;
            if (a != 0) {
              u = r / 100.0;
              v = g / 100.0;
              if (b == 0) {
                u = -u;
                v = -v;
              } else if (b == 1) {
                u = -u;
              } else if (b == 10) {
                v = -v;
              }
            }

            value_0 = { u: u, v, v };
            thisGridData[i][j] = value_0;
          }
        }
      }
      let uvData = thisGridData;
      let elLayer1 = windFeatherLayer({
        zIndex: 30,
        startLat: dataRange.startLat,
        endLat: dataRange.endLat,
        startLon: dataRange.startLon,
        endLon: dataRange.endLon,
      });
      elLayer1.addTo(thisLayerG);
      elLayer1.SetData(uvData);
      // 记录图层
      Config.activeLayers[layerKey] = elLayer1;
      return;
    }
    if (dataType == "wind") {
      let ParticleSet = {
        zIndex: 200,
        // color: ["rgb(255, 0, 0)"],
        color: ["rgb(255, 255, 255)"],
        velocityScale: 0.005, //步长，流动速度(尽量不变)
        globalAlpha: 0.9, //全局透明度
        particleAge: 30, //粒子生命周期
        particleMultiplier: 400, //密度
        frame_rate: 30, //刷新率
        lineWidth: 1.5, //线宽
        arrow: false,
        particle: true,
        calRegion: calRegion,
        uData: thisUData,
        vData: thisVData,
        range: dataRange,
      };
      if (pa.attribute.showArrow) {
        ParticleSet.arrow = true;
        ParticleSet.particle = false;
      }
      let elLayer1 = ParticleLayer(ParticleSet);
      elLayer1.addTo(thisLayerG);
      elLayer1._setdata();
      // 记录图层
      Config.activeLayers[layerKey] = elLayer1;
    } else if (dataType == "current") {
      let ParticleSet = {
        zIndex: 200,
        color: ["rgb(255, 81, 0)"],
        velocityScale: 0.08, //步长，流动速度(尽量不变)
        globalAlpha: 0.95, //全局透明度
        particleAge: 90, //粒子生命周期
        particleMultiplier: 600, //密度
        frame_rate: 35, //刷新率
        lineWidth: 2, //线宽
        arrow: false,
        particle: true,
        calRegion: calRegion,
        uData: thisUData,
        vData: thisVData,
        range: dataRange,
      };
      if (!pa.attribute.showLand) {
        addnosea();
      }
      if (pa.attribute.showArrow) {
        ParticleSet.arrow = true;
        ParticleSet.particle = false;
      }
      let elLayer1 = ParticleLayer(ParticleSet);
      elLayer1.addTo(thisLayerG);
      elLayer1._setdata();
      // 记录图层
      Config.activeLayers[layerKey] = elLayer1;
      addnosea();
    } else {
      let option = {
        zIndex: 10,
        showLabel: false,
        opacity: 0.9,
        scalarColor: Config.scalarColor[dataType],
        range: dataRange,
      };
      if (pa.attribute.showLabel) {
        option.showLabel = true;
      }
      let elLayer1 = ScalarLayer(option);

      elLayer1.addTo(thisLayerG);
      elLayer1.setData(thisGridData);
      // 记录图层
      Config.activeLayers[layerKey] = elLayer1;
      if (!pa.attribute.showLand) {
        addnosea();
      }
    }
  };
};
export let removeForecastLayer = () => {
  thisLayerG?.clearLayers();
  // 清理图层记录
  Config.activeLayers = {};
  removenosea();
};
let removenosea = () => {
  if (Config.mapObj.map.hasLayer(Config.AllLayers.tianditu_v_nosea)) {
    Config.mapObj.map.removeLayer(Config.AllLayers.tianditu_v_nosea);
  }
};
let addnosea = () => {
  if (!Config.mapObj.map.hasLayer(Config.AllLayers.tianditu_v_nosea)) {
    Config.AllLayers.tianditu_v_nosea.addTo(Config.mapObj.map);
  }
};

// 导出 Config 对象
export { Config };
